<template>
  <div>
    <router-view v-if="visible"/>
    <div v-else class="wfull flx-c" :style="{height:`${winHeight}px`}">加载中...</div>
  </div>
</template>

<script>
import storage from 'store'
import { ACCESS_TOKEN } from '@/store/mutation-types'
export default {
  data () {
    return {
      visible: false
    }
  },
  mounted () {
    window.onmessage = (event) => {
      if (typeof event.data === 'string' && event.data.startsWith('cas:')) {
        const str = event.data.substring(4)
        const json = JSON.parse(str)
        const itsToken = json.itsToken
        storage.set(ACCESS_TOKEN, itsToken, 7 * 24 * 60 * 60 * 1000)
      }
    }
    this.initVisible()
  },
  methods: {
    initVisible () {
      this.visible = this.checkToken()
      if (!this.visible) {
        setTimeout(() => {
          this.initVisible()
        }, 200)
      }
    },
    checkToken () {
      const token = storage.get(ACCESS_TOKEN)
      if (token) {
        return true
      } else {
        return false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
